


#include <systemc.h>
#include <list>
#include "BusInterface.hpp"
#include "Exception.hpp"
#include "SystemCDefinitions.hpp"
#include "Statistics.hpp"


#define	FiFoNamespaceBegin	namespace FiFo {
#define	FiFoNamespaceEnd	}


FiFoNamespaceBegin

using namespace Bus ;
using namespace SystemC ;





/*	Design Notes:
 
 Forced to 32-bit by using bus's "Word". The scope of this
 software will never extend to an (N!=32)-bit system.
 */


class WriteInterface : virtual public sc_interface
{
public:
	virtual void		write	( Word const & ) = 0 ;
	virtual Length		availableCapacity () const = 0 ;
	virtual sc_event const&	wasReadEvent () const = 0 ;
};

class ReadInterface : virtual public sc_interface
{
public:
	virtual Word const	read	() = 0 ;
	virtual Length		availableLength () const = 0 ;
	virtual sc_event const&	wasWrittenEvent () const = 0 ;
};




class Buffer : public sc_channel , public WriteInterface , public ReadInterface
{
public:
	Buffer	( sc_module_name const & inName , Length inCapacity , SCInterval const & inRWDelay ) ;
	~Buffer () ;
	
	
	virtual void		write	( Word const & inValue ) ;
	virtual Length		availableCapacity () const ;
	virtual Word const	read	() ;
	virtual Length		availableLength () const ;
	
	virtual sc_event const&	wasWrittenEvent () const ;
	virtual sc_event const&	wasReadEvent () const ;
	
	
private:
	std::list<Word>	mData ;
	Length			mCapacity ; // stores for queries
	sc_event		mWasWritten , mWasRead ;
	SCInterval		mRWDelay ;
	
	Stats::Accumulator<UInt32>	mTotalDataWritten ;
};






FiFoNamespaceEnd

